package com.jf.cloud.supplier.listener;

import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.supplier.bo.mongo.MongoSupplierWalletLogBO;
import com.jf.cloud.supplier.service.SupplierWalletLogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 添加供应商钱包日志至MongoDB
 * @author 菠萝凤梨
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ADD_SUPPLIER_WALLET_LOG_TOPIC, consumerGroup = RocketMqConstant.ADD_SUPPLIER_WALLET_LOG_TOPIC)
public class AddSupplierWalletLogConsumer implements RocketMQListener<List<MongoSupplierWalletLogBO>> {
    private static final Logger LOG = LoggerFactory.getLogger(AddSupplierWalletLogConsumer.class);

    @Autowired
    private SupplierWalletLogService supplierWalletLogService;

    @Override
    public void onMessage(List<MongoSupplierWalletLogBO> message) {
        LOG.info("通知添加供应商钱包日志至MongoDB开始... message: " + Json.toJsonString(message));
        supplierWalletLogService.saveMongoBatch(message);
        LOG.info("添加供应商钱包日志结束");
    }
}
